﻿using System;
using System.Collections.Generic;
using System.Linq;
using Viyi.Util.Linq;
using Xunit;
using Xunit.Abstractions;

namespace Viyi.Util.Test.Linq
{
    public class TestForEach
    {
        readonly ITestOutputHelper output;

        public TestForEach(ITestOutputHelper output)
        {
            this.output = output;
        }

        [Fact]
        public void TestAction()
        {
            Enumerable.Range(0, 10)
                .Select(n => n * n)
                .ForEach(n => output.WriteLine(n.ToString()));
        }

        [Fact]
        public void TestFunc()
        {
            Enumerable.Range(10, 10)
                .ForEach(n => n * 10);
        }

        [Fact]
        public void TestException()
        {
            Assert.Throws<ArgumentNullException>("source", () =>
            {
                IEnumerable<string> source = null;
                source.ForEach(t => t);
            });

            Assert.Throws<ArgumentNullException>("process", () =>
            {
                IEnumerable<string> source = new string[0];
                source.ForEach(null);
            });
        }
    }
}
